function sfcInit() {

    var advisedId = emosWS.getNewElementId();
    var appName = sessionStorage.getItem("apt_appName");
    var robName = sessionStorage.getItem("apt_AT_LastSelectedRobot");

    //zu ersetzen mit sfc.JSON
    var jsonPath = '../content/application/apps/' + appName + '/' + robName + '/sfc.JSON';
    var sfcLookup = [];
    var rawData = null; // Raw json without modifications. Used when switching the language to not have to call it again
    var prefix = "T02_";

    var stateTextAdvisedId;
    var sfcDropdownId = getElementGlobalID();
    var sfcDropdownListId = getElementGlobalID();

    var opc = sessionStorage.getItem("apt_" + robName + ".OpcTopic");
    var startTag = opc + sessionStorage.getItem("apt_" + robName + ".Tags.Sfc.Start"); //Start Tag für Start: SV_PCU2HMI.tFlowchart[1].sIn.i_mStart
    var startEnTag = opc + sessionStorage.getItem("apt_" + robName + ".Tags.Sfc.StartEnable"); //Enable Tag für Start: SV_PCU2HMI.tFlowchart[1].sOut.o_mStartEn
    var stopTag = opc + sessionStorage.getItem("apt_" + robName + ".Tags.Sfc.Stop"); //Start Tag für Stop: SV_PCU2HMI.tFlowchart[1].sIn.i_mStop
    var stopEnTag = opc + sessionStorage.getItem("apt_" + robName + ".Tags.Sfc.StopEnable"); //Enable Tag für Stop: SV_PCU2HMI.tFlowchart[1].sOut.o_mStopEn
    //Example for StartAll: var stopAllTag = opc + sessionStorage.getItem("apt_" + robName + ".Tags.TimeProgStopAll");
    //Example for StopAll:  var stopAllEnTag = opc + sessionStorage.getItem("apt_" + robName + ".Tags.TimeProgStopAllEnable");
    var sfcStatusTag = opc + sessionStorage.getItem("apt_" + robName + ".Tags.Sfc.Status"); //zu ersetzen mit SV_PCU2HMI.tFlowchart[1].sOut.o_iStatus
    var sfcNameTag = opc + sessionStorage.getItem("apt_" + robName + ".Tags.Sfc.Name"); //Schreibt ausgewältes Element: SV_PCU2HMI.tFlowchart[1].sOut.o_zName

    var sfcNameReq = opc + sessionStorage.getItem("apt_" + robName + ".Tags.Sfc.NameReq"); //Liest ausgewältes Element: SV_PCU2HMI.tFlowchart[1].sIn.i_zNameReq

    var descriptionNumber = opc + sessionStorage.getItem("apt_" + robName + ".Tags.Sfc.DescriptionNumber"); //Beschreibung des Elements: SV_PCU2HMI.tFlowchart[1].sOut.o_zStepDescription,No

    var languageTexts = {
        "T02_ActualSfc": {
            id: "actSfcText",
            text: "T02_ActualSfc"
        },
        "T02_Description": {
            id: "sfcDescription",
            text: "T02_Description"
        }
    };

    // Check if users have right to start 
    var userRightDisabledClass = "aptUserRightDisabled";
    if (checkAptUserRight(16)) {
        userRightDisabledClass = "";
    }

    function createDOM() {
        var dropDownElement = "<div class='inputGroup fl sfcDropCenter'>" +
            "<span class='dropdown emosbutton aptTextEllipsis sfcDropDown aptdropdown " + userRightDisabledClass + "' id='" + sfcDropdownId + "' ></span>" +
            "<ul class='dropdownlist aptDropdownlist sfcGroupDropdownList' id='" + sfcDropdownListId + "'></ul>" +
            "</div>";

        var contentGroup = "<div class='sfcSelection'>" + dropDownElement + "</div>";

        var contentButton = "<div id='sfcControlButtons'>" +
            "<span class='emosbutton sfcSpaceButtons aptStartButton disabled " + userRightDisabledClass + "' id='sfcStart'></span>" +
            "<span class='emosbutton sfcSpaceButtons aptStopButton disabled " + userRightDisabledClass + "' id='sfcStop'></span>" +
            /*"<span class='emosbutton sfcSpaceButtons aptSendToAllButton  " + userRightDisabledClass + "' id='sfcStartAll'></span>" +
            "<span class='emosbutton aptStopAllButton aptStandardButton " + userRightDisabledClass + "' id='sfcStopAll'></span>" +*/
            "</div>";

        $('#sfcDropdownId').empty();
        $('#sfcDropdownId').append(contentGroup);
        $('#sfcDropdownId').append(contentButton);

        $.ajax({
            url: jsonPath,
            type: 'post',
            dataType: 'json',
            async: false,
            cache: false,
            success: function(data) {
                rawData = data;
                groupArray();
            },
            error: function(jqXHR, textStatus, errorThrown) {
                AptWriteLog("[APT Error] Could not read " + jsonPath + ". Error: " + errorThrown + "", "error");
            }
        });
    }

    function groupArray() {
        rawData.names.forEach(function(group) {
            sfcLookup.push(group);
            buildGroupDropdown(sfcLookup.length - 1);
        });
    }

    function buildGroupDropdown() {
        var name = sfcLookup[index];
        $('#' + sfcDropdownListId).html("");
        sfcLookup.forEach(function(group) {
            $("<li/>", {
                "class": 'breadoverlay_li aptTextEllipsis ' + sfcDropdownListId,
                "text": group,
                "id": sfcDropdownListId + '_' + name,
                "data-num": index,
                "click": function() {
                    $(this).parent().addClass("aptHide");
                    $('#' + sfcDropdownId).removeClass("hovered");
                    $(this).siblings().removeClass("active");
                    $(this).addClass("active");

                    // Poke the selected name to IOM
                    emosWS.poke(sfcNameReq, group);

                    $('#' + sfcDropdownId).text(group);
                }
            }).appendTo($('#' + sfcDropdownListId));
        });
    }

    function dataHandler() {

        /*emosWS.advise(sfcStartEnTag, function(msg){
            if(msg.value !== "0"){
                $('#sfcStart').removeClass("disabled");
            }
            else{
                $('#sfcStart').addClass("disabled");
            }
        }).setId(advisedId);*/

        // Stop All button enabled
        /*emosWS.advise(sfcStopAllEnTag, function (msg) {
            if (msg.value !== "0") {
                $('#sfcStopAll').removeClass("disabled");
            }
            else {
                $('#sfcStopAll').addClass("disabled");
            }
        }).setId(advisedId);*/

        emosWS.advise(sfcNameTag, function(msg) {
            $('#actSfc').text(msg.value);
        }).setId(advisedId);

        emosWS.advise(descriptionNumber, function(msg) {
            $('#sfcDescriptionText').text(msg.value);
        }).setId(advisedId);

        emosWS.advise(startEnTag, function(msg) {
            if (msg.value == -1) {
                $('#sfcStart').removeClass("disabled");
            } else {
                $('#sfcStart').addClass("disabled");
            }
        }).setId(advisedId);

        emosWS.advise(stopEnTag, function(msg) {
            if (msg.value == -1) {
                $('#sfcStop').removeClass("disabled");
            } else {
                $('#sfcStop').addClass("disabled");
            }
        }).setId(advisedId);


        emosWS.advise(sfcStatusTag, function(msg) {

            emosWS.unadvise(stateTextAdvisedId);
            stateTextAdvisedId = emosWS.getNewElementId();

            var statusName;

            $('#sfcStatus').removeClass("aptChannelOk aptChannelError aptChannelWarning aptChannelUndefined aptChannelDisabled");
            var val = msg.value;

            if (val == 0) { //red, undefined
                statusName = "TP_State0"; //from TP Texts
                $('#sfcStatus').addClass("aptChannelError");
            } else if (val == 1) { //grey, stop
                statusName = "TP_State1";
                $('#sfcStatus').addClass("aptChannelUndefined");
            } else if (val == 2 || val == 4) { //green, running
                statusName = "TP_State4";
                $('#sfcStatus').addClass("aptChannelOk");
            } else {
                statusName = "TP_State0";
                $('#sfcStatus').addClass("aptChannelUndefined");
            }

            var textId = prefix + statusName;

            emosWS.sendAdviseText(textId, "name", function(msg) {
                $('#sfcStatus').text(msg.value);
            }).setId(stateTextAdvisedId);
        }).setId(advisedId);
    }

    function eventHandler() {

        $('#' + sfcDropdownId).mouseenter(function() {
            $('#' + sfcDropdownListId).removeClass("aptHide");
        });

        $('#sfcStart').click(function() {
            //emosWS.poke(stopAllTag, 0);
            emosWS.poke(stopTag, 0);
            emosWS.poke(startTag, 1);
            setTimeout(function() {
                emosWS.poke(startTag, 0);
            }, 1000);
        });

        $('#sfcStop').click(function() {
            emosWS.poke(startTag, 0);
            emosWS.poke(stopTag, 1);
        });

        $('#sfcStart').on('remove', function() {
            emosWS.unadvise(advisedId);
        });

        // On closing of the frame, remove the data listener from emosWS
        $("#sfcContainer").on("remove", function() {
            emosWS.unadvise(advisedId);
        });
    }

    languageHandler(languageTexts);
    createDOM();
    dataHandler();
    eventHandler();

}